﻿Public Class frmProfile 
    Private WithEvents userSocks As Connections

    Private Sub frmProfile_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        userSocks = SockGlobal
        userSocks.getUserData()
    End Sub

    Private Sub setBox(ByVal nickname As String)
        txtOPassword.Text = ""
        txtnPassword.Text = ""
        txtcnPassword.Text = ""
        txtNickname.Text = nickname
    End Sub

    Private Sub showMessages(ByVal msg As String)
        MsgBox(msg, MsgBoxStyle.Exclamation, "Warning")
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        userSocks.setUserData(txtOPassword.Text, txtnPassword.Text, txtcnPassword.Text, txtNickname.Text)
    End Sub

    Private Sub userSocks_dataResponse(response() As String) Handles userSocks.dataResponse
        If response.Length > 1 Then
            If response(0).Equals("10") Then
                If response(1).Equals("1") Then
                    Me.Invoke(Sub() setBox(response(2)))
                ElseIf response(1).Equals("2") Then
                    Select Case response(2)
                        Case "0"
                            Me.Invoke(Sub() setBox(response(3)))
                            Me.Invoke(Sub() frmMain.BarStaticItemConnection.Caption = "Connected as " & response(3))
                            Me.Invoke(Sub() showMessages("User Data has Changed!"))
                        Case Else
                            Me.Invoke(Sub() showMessages("User Data Change Failed" & vbCrLf & "Reason: " & getResponseMsg(response(0), response(1), response(2))))
                    End Select
                End If
            End If
        End If
    End Sub

    Private Sub SimpleButtonExit_Click(sender As Object, e As EventArgs) Handles SimpleButtonExit.Click
        Me.Close()
    End Sub
End Class